package com.aaa.dao;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

/**
 * @Author: TT
 * @Date: 2019/3/12 20:42
 * @Version 1.0
 */

public interface T_QuestionsDao {
    @Select("<script>SELECT a.id,a.question,a.optiona,a.optionb,a.optionc,a.answer,a.questiontypeid,a.year,b.typename,c.`name`  from t_questions a " +
            " join t_question_type b  ON  a.questiontypeid=b.id " +
            " JOIN `year` c on c.id =a.`year` where 1=1 <if test=\"year!=null and year!=0\">"+
            "and a.year=#{year}</if><if test=\"question=null and question!=''\" >"+
            " and a.question like concat('%',#{question},'%')</if> limit #{start},#{pageSize}</script>")
    List<Map> Select(Map map);
    @Select("<script>select count(id) from t_questions where 1=1 <if test=\"year!=null and year!=0\">"+
            "and id=#{id}</if> <if test=\"question=null and question!=''\">"+
            " and question like concat('%',#{question},'%')</if></script>")
    Integer Count(Map map);
    @Delete("delete from t_questions where id=#{id}")
    Integer Del(Map map);
    @Update("update t_questions set question=#{question},optiona=#{optiona},optionb=#{optionb}," +
            "optionc=#{optionc},answer=#{answer},questiontypeid=#{questiontypeid},year=#{year}" +
            " where id=#{id}")
    Integer Update(Map map);
    @Insert("insert into t_questions(question,optiona,optionb,optionc,answer,questiontypeid,year)" +
            "values(#{question},#{optiona},#{optionb},#{optionc},#{answer},#{questiontypeid},#{year})")
    Integer Insert(Map map);
    @Select("select * from year")
    List<Map> Year();
    @Select("select * from t_question_type")
    List<Map> type();
    @Delete("delete from t_questions where id=#{id}")
    Integer dels(String id);
}
